#line 1 "D:/Archivio/mikroC/tric-ricotta/rx.c"
#line 1 "d:/archivio/mikroc/tric-ricotta/config.h"
#line 1 "d:/archivio/mikroc/tric-ricotta/rx.h"



void RX_processValues(unsigned short *RX_interruptTimer, float *RX_values);
void RX_applyThrottleToMotors(float *RX_angle, unsigned short *MOTORS_speed);
#line 11 "D:/Archivio/mikroC/tric-ricotta/rx.c"
void RX_processValues(unsigned short *RX_interruptTimer, float *RX_values) {
 unsigned short cnt;
 unsigned short zerocross;
 float RX_conversionFactor;

 RX_conversionFactor = 180.0 /  194 ;

 for(cnt=0; cnt<7; cnt++) {
 if (RX_interruptTimer[cnt] == 255) zerocross = cnt;
 }
 for(cnt=zerocross+1; cnt<7; cnt++) {
 if (RX_conversionFactor * RX_interruptTimer[cnt] >  90 ) RX_values[cnt-zerocross-1] =  90 ;
 else if (RX_conversionFactor * RX_interruptTimer[cnt] <  -90 ) RX_values[cnt-zerocross-1] =  -90 ;
 else RX_values[cnt-zerocross-1] = RX_conversionFactor * RX_interruptTimer[cnt];

 }
 for(cnt=0; cnt<zerocross; cnt++) {
 if (RX_conversionFactor * RX_interruptTimer[cnt] >  90 ) RX_values[cnt+6-zerocross] =  90 ;
 else if (RX_conversionFactor * RX_interruptTimer[cnt] <  -90 ) RX_values[cnt+6-zerocross] =  -90 ;
 else RX_values[cnt+6-zerocross] = RX_conversionFactor * (RX_interruptTimer[cnt] -  96 );

 }

 for(cnt=0; cnt<6; cnt++) {
 switch(cnt) {
 case 2: if (1.41666 * RX_values[cnt] >  255 ) RX_values[cnt] =  255 ;
 else if (1.41666 * RX_values[cnt] <  0 ) RX_values[cnt] =  0 ;
 else RX_values[cnt] = 1.41666 * RX_values[2];
 break;
 default: RX_values[cnt] -= 90;
 break;
 }
 }
}

void RX_applyThrottleToMotors(float *RX_values, unsigned short *MOTORS_speed) {
 unsigned short cnt;

 for(cnt=0; cnt<3; cnt++) {
 if ( 0.9  * RX_values[2] >  250  ) MOTORS_speed[cnt] =  250  ;
 else if ( 0.9  * RX_values[2] <  20  ) MOTORS_speed[cnt] =  20  ;
 else MOTORS_speed[cnt] +=  0.9  * RX_values[2];
 }
}
